package com.stud.framework.aspectj;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.filter.PropertyFilter;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author: Stud
 * @create: 2021-12-08 14:16
 **/
@Slf4j
@Aspect
@Component
public class StudParameterAspect {

    @Pointcut("execution(public * com.stud.*.controller..*.*(..))")
    public void pointcut() {

    }

    @Before(value = "pointcut()")
    public void before(JoinPoint joinPoint) {
        try {
            PropertyFilter filter = (object, name, value) -> !(object instanceof MultipartFile || object instanceof File);
            log.info(joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + " 方法入参:" + JSON.toJSONString(joinPoint.getArgs(), filter));
        } catch (Exception ignored) {

        }
    }

    @AfterReturning(returning = "result", value = "pointcut()")
    public void after(Object result) {
        log.info("方法出参:" + JSON.toJSONString(result));
    }

}
